<template>
  <div class="risk">
    <!-- <van-search
      class="info_search input_text"
      v-model="value"
      @search="onSearch"
      placeholder="搜索"
	  v-if="active === 1"
    /> -->
    <eagle-tab-page-list
      :url="url"
      :params="params"
      :filterParams="filterParams"
      :filterTab="filterTab"
      noNeedData=0
      @initActive="_initActive"
      @initList="_initList"
      ref="eagleTabPageList"
    >
      <template v-if="active === 0">
        <div class="report-list mt-10">
          <div class="mb-20">
            <div class="report-title">生成检查报告</div>
            <div class="report-btns">
              <eagle-button
                class="submit-btn"
                type="primary"
                @click="_goTaskReport"
              >
                按任务生成
              </eagle-button>
              <eagle-button
                class="submit-btn"
                type="info"
                @click="_goHiddenDangerReport"
              >
                按隐患生成
              </eagle-button>
            </div>
          </div>
          <div>
            <div class="report-title">生成整改报告</div>
            <div class="report-btns">
              <eagle-button
                class="submit-btn"
                type="primary"
                @click="_goCorrectiveReport"
              >
                按任务生成
              </eagle-button>
              <eagle-button
                class="submit-btn"
                type="info"
                @click="_goCorrectiveReportByDanger"
              >
                按隐患生成
              </eagle-button>
            </div>
          </div>
        </div>
      </template>
      <template v-if="active === 1">
        <div class="tab-content">
          <van-list :finished="finished" v-model="loading" @load="onLoad">
            <eagle-cell
              class="mb-10 mt-10 br-8"
              v-for="(item, index) in list"
              :key="index"
            >
              <div class="warn_item">
                <div>
                  <div class="dep_sort_name">{{ item.Name }}</div>
                  <eagle-row gutter="20" class="dep_sort">
                    <eagle-col span="24">
                      <img
                        src="@/assets/Images/AppIcon/icon_list_enterprise.png"
                        alt=""
                      />{{ item.EnterpriseName }}
                    </eagle-col>
                  </eagle-row>
                  <eagle-row gutter="20" class="dep_sort">
                    <eagle-col span="24">
                      <img
                        src="@/assets/Images/AppIcon/icon_list_type.png"
                        alt=""
                      />{{ item.CheckTypeName }}
                    </eagle-col>
                  </eagle-row>
                  <eagle-row gutter="20" class="dep_sort">
                    <eagle-col span="24">
                      <img
                        src="@/assets/Images/AppIcon/icon_list_kind.png"
                        alt=""
                      />{{ item.ReportName || "" }}
                    </eagle-col>
                  </eagle-row>
                  <eagle-row gutter="20" class="dep_sort">
                    <eagle-col span="10">
                      <img
                        src="@/assets/Images/AppIcon/icon_equ_type.png"
                        alt=""
                      />{{
                        item.ReportType==1? "检查报告": "整改报告"
                      }}
                    </eagle-col>
                    <eagle-col span="14">
                      <img
                        src="@/assets/Images/AppIcon/icon_list_danger.png"
                        alt=""
                      />隐患：{{ item.HiddenDangerCnt }}
                    </eagle-col>
                  </eagle-row>
                  <eagle-row gutter="20" class="dep_sort">
                    <eagle-col span="10">
                      <img
                        src="@/assets/Images/AppIcon/icon_list_user.png"
                        alt=""
                      />{{ item.CreateChnName }}
                    </eagle-col>
                    <eagle-col span="14">
                      <img
                        src="@/assets/Images/AppIcon/icon_list_date.png"
                        alt=""
                      />{{ item.CreateDate | formatDateTime }}
                    </eagle-col>
                  </eagle-row>
                </div>
              </div>
              <div style="display: flex;justify-content: space-between;">
              <div class="look-report" @click="deletePdf(item)">
                    <img
                      src="@/assets/Images/AppIcon/icon_list_delete.png"
                      alt=""
                    />
                    <span>删除报告</span>
                  </div>
              <div class="look-report" @click="lookPdf(item)">
                <img
                  src="@/assets/Images/AppIcon/icon_list_review.png"
                  alt=""
                />
                <span>查看报告</span>
              </div>
            </div>
            </eagle-cell>
          </van-list>
        </div>
      </template>
    </eagle-tab-page-list>
  </div>
</template>

<script>
import { getDate } from "@/utils/getDate";
import deepClone from '../../../utils/deepClone';
export default {
  data() {
    return {
      url:'/DangerReport/GetPageData',
      title: "",
      active: 0,
      value: "",
      list: [],
      filter: {
        page: 0,
        dataType: "ReportHistory",
        conditions:''
      },
      loading: false,
      finished: false,
      baseUrl: process.env.VUE_APP_BASE_API,
      tabTitle: [{ title: "生成报告" }, { title: "报告历史" }],
      params: [
        {
          title: "生成报告",
          dataType: "",
        },
        {
          title: "报告历史",
          dataType: "ReportHistory",
        }
      ],
      value1:0,
      value2:'a',
      option1: [
        { text: '全部', value: 0 },
        { text: '检查报告', value: 1 },
        { text: '整改报告', value: 2 },
      ],
      option2: [
        { text: '全部', value: 'a' },
        { text: '通用隐患整改报告', value: 'b' },
        { text: '通用隐患检查报告', value: 'c' },
      ],
      filterParams:[],
      filterTab: true,
   filterParams2:[
     {
            name: "ReportType",
            title: "全部",
            originTitle: "全部",
            dataType: "int",
            data: [
              { text: "全部", value: "" },
              { text: "检查报告", value: "1" },
              { text: "整改报告", value: "2" },
            ],
          },
          {
            name: "ReportCode",
            title: "全部",
            originTitle: "全部",
            dataType: "string",
            data: [
            { text: "全部", value: "" },
            { text: '全覆盖检查（巡查）报告', value: 'DangerCheckCoverReportJG' },
            { text: '全覆盖检查（巡查）复查报告', value: 'DangerCorrectiveCoverReportJG' },
            ],
          },
        ]
    };

  },
  created() {
    if(this.$store.state.CompanyType==='JG'){
      this.url='/DangerReportJG/GetPageData'

    }
    this.getParams()
  },
  methods: {
    _initActive(active) {
      this.active = active;
      this.filterTab = active==0?false:true;
      this.filterParams=this.filterParams2
      
    },
    _initList(list) {
      this.list = list;
    },
    onSearch() {
      this.filter.page = 0;
      this.filter.keywords = this.value;
      this.getList();
    },
    clearSearch() {
      this.filter.page = 0;
      this.filter.keywords = "";
      this.getList();
    },
    changeTabs(active) {
      this.active = active;
      this.filter.page = 0;
      this.getList();
    },
    getList(value) {
      this.loading = true;
      let _this = this;

      // 筛选
      _this.filter.conditions=JSON.stringify([{IsTemp:false,
            Name:"ReportCode",
            Operator:"\u003d",
            Value:value}])
          
      console.log(_this.filter.conditions)
      
      _this.$axios
        .get(this.url, { params: _this.filter })
        .then((res) => {
          _this.loading = false;
          if (!res.data.HasNextPage) {
            _this.finished = true;
          }
          _this.list = res.data.Data;
          _this.filter.page = res.data.PageIndex;
          
        });
    },
    onLoad() {
      console.log('load')
      this.loading = true;
      ++this.filter.page;
      let _this = this;
      _this.$axios
        .get(this.url, { params: _this.filter })
        .then((res) => {
          _this.loading = false;
          res.data.Data.forEach((item) => {
            item.CreateDate = getDate(item.CreateDate);
          });
          _this.filter.page = res.data.PageIndex;
          _this.list = _this.list.concat(res.data.Data);
          if (!res.data.HasNextPage) {
            _this.finished = true;
          }
        });
    },

    // 检查报告
    _goTaskReport() {
      this.title = "生成检查报告(按任务)";
      this.$router.push({
        path: "/Danger/TaskReport",
        query: { type: "Task", reportType: "1" },
      });
    },
    // 隐患生成
    _goHiddenDangerReport() {
      this.title = "生成检查报告(按隐患)";
      this.$router.push({
        path: "/Danger/HiddenDangerReport",
        query: { type: "TaskDetail", reportType: "1" },
      });
    },
    // 整改报告
    _goCorrectiveReport() {
      this.title = "生成整改报告(按任务)";
      this.$router.push({
        // path: '/Danger/TaskReport',
        path: "/Danger/CorrectiveReport",
        query: { type: "Task", reportType: "2" },
      });
    },
    // 整改隐患
    _goCorrectiveReportByDanger() {
      this.title = "生成整改报告(按隐患)";
      this.$router.push({
        // path: '/Danger/HiddenDangerReport',
        path: "/Danger/CorrectiveHiddenDanger",
        query: { type: "TaskDetail", reportType: "2" },
      });
    },
    // 查看报告
    lookPdf(item) {
      // this.title = "报告详情"
      // this.$router.push("/Attach/AatachDetail?url=" + this.baseUrl + item.Attachs);
      // 打开新窗口
      // window.open(this.baseUrl + item.Attachs)
      console.log(111,item)
      this.title = "报告详情";
      this.$router.push({
        name: "CheckReportDetail",
        query: {
          // url: this.baseUrl + item.Attachs,
          url:
            // "https://afx.ehsway.com" +
            // "/Plugins/pdfjs/web/viewer.html?file=" +
            // item.Attachs,
            // "http://chsyat.safetyhua.com/"  +
            process.env.VUE_APP_BASE_API+
            item.Attachs,
            isSign:item.IsSign,
            signState:item.SignState
        },
      });
  
    },
    getParams(){
        //InfoReportDefine/GetDefines
        let _this = this;
        _this.$axios
        .get("/InfoReportDefine/GetDefines", { params: {jgType:"normal"}})
        .then((res) => {
         res.data.forEach((item)=>{
            item.text=item.Name
            item.value=item.ID
            console.log(item)
            _this.filterParams2[1].data.push(item)
         
          })
          
          
        });
       
      },
    menuChange1(value){
      if(value === 0){
        this.getList()
      }else if(value === 1){
        this.getList('DangerCheckReportRA')
      }else if(value === 2){
        this.getList('DangerCorrectiveReportRA')
      }
    },
    menuChange2(value){
      if(value === 'a'){
        this.getList()
      }else if(value === 'b'){
        this.getList('DangerCheckReportRA')
 
      }else if(value === 'c'){
        this.getList('DangerCorrectiveReportRA')
      
      }
    },
        // 删除报告
        deletePdf(item) {
      let _this=this;
      _this.$dialog.confirm({
      title: "询问",
      message: "您确定要删除当前报告吗?",
      })
        .then(() => {
          // on confirm
          _this.$axios
          .get("/DangerReportJG/DeletePost",{ params:{ reportId: item.ID }})
          .then((res)=>{
            _this.$toast.success("删除成功！");
            _this.$refs.eagleTabPageList.getList();
          })
        })
        .catch(() => {
          // on cancel
        });

    },
  },
};
</script>

<style lang="less" scoped>
.risk {
  background-color: #e8f1f8;
  .info_search {
    padding: 10px;
    border-radius: 5px !important;
    .van-field__control {
      background-color: #ffffff !important;
    }
  }
}

.tab-content {
  padding: 0 10px;
  font-size: 14px;
  img {
    height: 15px;
    width: 15px;
    margin-right: 5px;
  }
}
.look-report {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 10px;

  font-size: 12px;
  color: #666;
  border-top: 1px solid #eee;
}
.all_dep {
  background-color: #ffffff;
}
.warn_item {
  background-color: #ffffff;
  /*margin-bottom: 10px;*/
  // padding: 10px 0 10px 10px;
  border-radius: 5px;
  position: relative;
}
.warn_header {
  display: flex;
  justify-content: space-between;
  position: relative;
  margin-bottom: 10px;
  .warn_tag {
    position: absolute;
    right: 0;
    top: 0;
    border-radius: 26.64rem 0 0 26.64rem;
  }
}
.dep_sort_name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dep_btm {
  display: flex;
  justify-content: flex-end;
  .btm_item {
    display: flex;
    align-items: center;
    img {
      height: 15px;
      width: 15px;
      margin-right: 5px;
    }
  }
}
.report-list {
  height: 100vh;
  background-color: #fff;
  overflow: hidden;
}
.report-title {
  width: 100px;
  font-size: 15px;
  text-align: center;
  margin: 40px auto;
  padding-bottom: 10px;
  border-bottom: 1px solid #ccc;
}
.report-btns {
  margin-top: 10px;
  padding: 0 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  .submit-btn {
    width: 40%;
    height: 35px;
    font-size: 14px;
  }
}
</style>
